
#if !defined(AFX_KOSWIN_H__DB686B70_4731_4467_ABDD_410A573A9632__INCLUDED_)
#define AFX_KOSWIN_H__DB686B70_4731_4467_ABDD_410A573A9632__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

//be sure to set /TP compiler option to force compilation of c files as c++

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#include <windows.h>
//#include <GL/glu.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <malloc.h>
#include <math.h>
int fs_open(const char* filename, int openflag);
#define fs_close _close
#define fs_read(file,buffer,size) _read(file,buffer,size)
#define fs_tell(file) _tell(file)
#define fs_seek(file, len, opts) _lseek(file, len, opts)
#define fcos(val) (float)cos(val)
#define fsin(val) (float)sin(val)
#define fsqrt(val) ((float)sqrt(val))

#ifndef uint8
#define uint8 unsigned char
#endif
#ifndef uint16
#define uint16 unsigned short
#endif
#ifndef uint32
#define uint32 unsigned long
#endif

#define ANALOGMAIN
#define GL_KOS_VFZ_CLIPPING 0

// C RunTime Header Files
#include <stdlib.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "WinInput.h"


int SystemUpdate();
int GameLoop(); 

//extern agmmodel mod_echo;
//extern GLuint tex_echo;
//extern float ry;
extern DWORD KoswinNewTime,KoswinOldTime;
extern HDC hDC;				/* device context */
extern HWND hWnd;				/* device context */

extern WinInput JoyInput;

#define PNG_NO_ALPHA 0
#define PNG_MASK_ALPHA 1
#define PNG_FULL_ALPHA 2
#define DBGOUTP(string,x) {} //MessageBox(NULL,string,"DBG",MB_OK);
#define DBGOUT(string) {} //MessageBox(NULL,string,"DBG",MB_OK);
#define DBGOUT3(string,x,y,z) {} //MessageBox(NULL,string,"DBG",MB_OK);

#define CONT_C			(1<<0)
#define CONT_B			(1<<1)
#define CONT_A			(1<<2)
#define CONT_START		(1<<3)
#define CONT_DPAD_UP		(1<<4)
#define CONT_DPAD_DOWN		(1<<5)
#define CONT_DPAD_LEFT		(1<<6)
#define CONT_DPAD_RIGHT		(1<<7)
#define CONT_Z			(1<<8)
#define CONT_Y			(1<<9)
#define CONT_X			(1<<10)
#define CONT_D			(1<<11)
#define CONT_DPAD2_UP		(1<<12)
#define CONT_DPAD2_DOWN		(1<<13)
#define CONT_DPAD2_LEFT		(1<<14)
#define CONT_DPAD2_RIGHT	(1<<15)

/* Raw controller condition structure */
typedef struct {
	uint16 buttons;			/* buttons bitfield */
	uint8 rtrig;			/* right trigger */
	uint8 ltrig;			/* left trigger */
	uint8 joyx;			/* joystick X */
	uint8 joyy;			/* joystick Y */
	uint8 joy2x;			/* second joystick X */
	uint8 joy2y;			/* second joystick Y */
} cont_cond_t;


#define MAPLE_FUNC_PURUPURU		0x00010000
#define MAPLE_FUNC_MOUSE		0x00020000
#define MAPLE_FUNC_CONTROLLER		0x01000000
#define MAPLE_FUNC_MEMCARD		0x02000000
#define MAPLE_FUNC_LCD			0x04000000
#define MAPLE_FUNC_CLOCK		0x08000000
#define MAPLE_FUNC_MICROPHONE		0x10000000
#define MAPLE_FUNC_ARGUN		0x20000000
#define MAPLE_FUNC_KEYBOARD		0x40000000
#define MAPLE_FUNC_LIGHTGUN		0x80000000

typedef struct maple_device {
/*	// Public 
	int			valid;		// Is this a valid device? 
	int			port, unit;	// Maple address 
	maple_devinfo_t		info;		// Device info struct

	// Private 
	int			dev_mask;	// Device-present mask for unit 0's 
	maple_frame_t		frame;		// Give each device one rx/tx frame 
	struct maple_driver *	drv;		// Driver which handles this device 

	volatile int		status_valid;	// Have we got our first status update? 
	uint8			status[1024];	// Status buffer (for pollable devices) 
*/
} maple_device_t;


int cont_get_cond(uint8 c,cont_cond_t* cond);
maple_device_t* maple_enum_type(int n, uint32 func);


typedef struct {
	uint32	buttons;		/* Buttons bitfield */
	int	ltrig, rtrig;		/* Triggers */
	int	joyx, joyy;		/* Joystick X/Y */
	int	joy2x, joy2y;		/* Second Joystick X/Y (if applicable) */
} cont_state_t;

void* maple_dev_status(maple_device_t *dev);


void glKosBeginFrame();
void glKosFinishList();
void glKosFinishFrame();
void loadjpg(const char *fn, uint32 width, GLuint *txr);
void loadpng(const char *fn, uint32 alpha, GLuint *txr);
int snd_stream_init(char* unkn);
int snd_sfx_load(char* sound);
int	snd_sfx_unload_all();
int	snd_stream_shutdown();
void snd_sfx_play(int idx, int vol, int pan);
void vid_screen_shot(char*);
void glKosShutdown();
void glKosInit();
void pvr_init();
void KOS_INIT_ROMDISK();

int maple_first_controller();

struct timeval {
	long	tv_sec;		/* Seconds */
	long	tv_usec;	/* Microseconds */
};

/* We don't support time zones, but put it here for compatability */
struct timezone {
	int	tz_minuteswest;
	int	tz_dsttime;
};
void gettimeofday(timeval* time, timezone* tz);

#endif // !defined(AFX_KOSWIN_H__DB686B70_4731_4467_ABDD_410A573A9632__INCLUDED_)
